package com.sskj.quantization.ui.activity;


import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bulong.rudeness.RudenessScreenHelper;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.mvchelper.ModelRx2DataSource;
import com.sskj.quantization.R;
import com.sskj.quantization.R2;
import com.sskj.quantization.bean.ProfitAllBean;
import com.sskj.quantization.bean.ProfitBean;
import com.sskj.quantization.presenter.ProfitActivityPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

@Route(path = RConfig.QUAN_PROFIT)//我的收益
public class ProfitActivity extends BaseActivity<ProfitActivityPresenter> {
    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.coolRefreshView)
    CoolRefreshView coolRefreshView;
    @BindView(R2.id.tvProfit)
    TextView tvProfit;
    private SlimAdapter slimAdapter;
    private MVCCoolHelper<List<ProfitBean>> mvcHelper;

    @Override
    protected int getLayoutId() {
        return R.layout.quan_activity_profit;
    }

    @Override
    public ProfitActivityPresenter getPresenter() {
        return new ProfitActivityPresenter();
    }

    @Override
    protected void initView() {
        setTitle(App.INSTANCE.getString(R.string.quan_profitActivity1_h));
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 20))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.transparent))
        );
        // 剩余数量
        slimAdapter = SlimAdapter.create().register(R.layout.quan_recy_item_profit, new SlimInjector<ProfitBean>() {
            @Override
            public void onInject(ProfitBean data, IViewInjector injector, List payloads) {
                injector
                        .text(R.id.tvNum, data.getCon_no())
                        .text(R.id.tvMoney, data.getProfit())
                        .text(R.id.tvTime, data.getAddtime())
                ;
            }
        });
        slimAdapter.attachTo(recyclerView).updateData(new ArrayList());
        ModelRx2DataSource<ProfitBean> dataSource = new ModelRx2DataSource<>((ModelRx2DataSource.OnLoadSource<ProfitBean>)
                page -> mPresenter.getProfitList(page + "", "20"), 20);
        mvcHelper = new MVCCoolHelper<>(coolRefreshView);
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(slimAdapter);
        mvcHelper.refresh();
    }

    @Override
    protected void initData() {

        mPresenter.getProfit();
    }

    public void updateUI(ProfitAllBean data) {
        tvProfit.setText(data.getCount_profit());
    }
}
